<?php

namespace beObject\Exceptions;

use beObject\Primitive\String;
use beObject\Primitive\Boolean;
use beObject\Utils\ArrayList;

class ValidationException
    extends BeObjectException {

  /**
   * The collection of errors.
   * @var array
   */
  private $errors = array();

  /**
   * Regular expression to match french date format.
   * @var RegExp
   */
  protected static $__REGEXP_DATE_FR = "#^([0][0-9]|[1][0-9]|[2][0-9]|[3][01])/([0][1-9]|[1][012])/[0-9][0-9][0-9][0-9]$#";

  /**
   * Regular expression to match RNPP.
   * @var RegExp
   */
  protected static $__REGEXP_RNPP = "#^[0-9]{11}$#";

  /**
   * Regular expression to match BCE company number.
   * @var RegExp
   */
  protected static $__REGEXP_BCE_NUMBER = "#^[0-9]{10}$#";

  /**
   * Store the parameter in private of BeObjectException class.<br />
   *
   * @param string $message The message of the exception.
   * @link http://be2.php.net/manual/en/class.exception.php
   * @link http://fr2.php.net/manual/en/function.is-string.php
   * @link http://be.php.net/manual/en/function.empty.php
   */
  public function __construct(String $message) {
    $this->message = $message();
  }

  /**
   * Stack an error message associated to a key.
   * @param string $key The key.
   * @param string $value The message.
   * @link http://be2.php.net/manual/en/function.array-key-exists.php
   * @link http://be2.php.net/manual/en/function.array-push.php
   */
  public function addErrorMessage(String $key, String $value) {
    if (empty($this->errors[$key()])) {
      $this->errors[$key()] = array();
    }

    array_push($this->errors[$key()], $value());
  }

  /**
   * Gets the errors.
   * @return mixed Returns the array of errros if it's not empty, FALSE otherwise.<br />
   */
  public function getErrors() {
    return $this->errors;
  }

  /**
   * Defines if there is some errors or not.<br />
   * @return \beObject\Primitive\Boolean True if there is one or more errors.<br />
   * @link http://be2.php.net/manual/en/function.count.php
   */
  public function hasErrors() {
    return new Boolean(!empty($this->errors));
  }

}

?>
